﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MagicArenaFramework.GameObject.Components;

namespace MagicArenaXNA.GameObject.Spells
{
    public abstract class SpellBase : GoComponent
    {
        public enum SpellSchool { Red, Blue, Green, Brown }
        public enum SpellTarget { Other, Self }

        public SpellBase()
        {
            this.UpdateDel = MyUpdate;
        }

        public abstract SpellSchool School { get;}
        public abstract SpellTarget Target { get; }
        public abstract UInt64 SpellId { get; }
        public abstract float CastTime { get;}
        public abstract float ManaCost { get;}
        /// <summary>
        /// The cooldown that will be invoked if this spell is cast
        /// </summary>
        public abstract float CastCooldown { get;}
        /// <summary>
        /// The current cooldown this spell is on. This may be the CastCooldown or a cooldown from an external source
        /// </summary>
        private float _CurrentCooldown;
        public float CurrentCooldown
        {
            get { return _CurrentCooldown; }
            set
            {
                _CurrentCooldown = value;
                ellapsedTime = _CurrentCooldown;
            }
        }
        /// <summary>
        /// The percentage of CurrentCooldown which has completed
        /// </summary>
        public float CurrentCooldownPercent
        {
            get
            {
                float rtn = _CurrentCooldown > 0 ? ellapsedTime / _CurrentCooldown : 0;
                rtn = rtn < 0 ? 0 : rtn;
                return rtn;
            }
        }
        public abstract bool IsCasting { get;}
        public abstract float CastingTimeLeft { get;}

        float ellapsedTime = 0;
        protected void MyUpdate(float dt)
        {
            ellapsedTime -= dt;
        }
    }
}
